package com.smallprogram.www.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.smallprogram.www.comm.ServiceCode;
import com.smallprogram.www.entity.ResultEntity;
import com.smallprogram.www.model.Ordered;
import com.smallprogram.www.service.OrderedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author hj
 * @since 2020-10-05
 */
@RestController("/ordered")
public class OrderedController {

    private static final Logger log = LoggerFactory.getLogger(OrderedController.class);

    @Autowired
    private  OrderedService orderedService;
    @GetMapping("/ordered")
    public ResultEntity<Object> ordered(){
        Wrapper<Ordered> queryWrapper = new QueryWrapper(null);
        ResultEntity<Object> resultEntity =
                new ResultEntity<Object>(ServiceCode.SEUCCESS.getCode(),ServiceCode.SEUCCESS.getMessage(),orderedService.list(queryWrapper));
        return resultEntity;
    }

    @PostMapping("/ordered")
    public ResultEntity save(@RequestBody Ordered ordered){
        boolean bool = orderedService.save(ordered);
        if(bool){
            return  new ResultEntity(ServiceCode.SEUCCESS.getCode(),ServiceCode.SEUCCESS.getMessage());
        }else {
            return new ResultEntity(ServiceCode.FAIL.getCode(),ServiceCode.FAIL.getMessage());
        }
    }

}

